package cn.com.edaily.common;

import java.io.Serializable;

public class Response<T> implements Serializable {

	private static final long serialVersionUID = 8280226731472760259L;

	private Boolean success;

	private String code;

	private String message;

	private T data;

	public Response() {
	}

	public Response(Boolean success, T data) {
		this.success = success;
		this.data = data;
	}

	public Response(Boolean success, String message) {
		this.success = success;
		this.message = message;
	}

	public Response(Boolean success, String code, T data) {
		this.success = success;
		this.code = code;
		this.data = data;
	}

	public Response(Boolean success, String code, String message, T data) {
		this.success = success;
		this.code = code;
		this.message = message;
		this.data = data;
	}

	/**
	 * @return Response<String>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static Response success(String message) {
		return new Response(true, message);
	}

	/**
	 * @return Response<T>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static <T> Response<T> success(T data) {
		return new Response<T>(true, data);
	}

	/**
	 * @return Response<T>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static <T> Response<T> success(String code, String message, T data) {
		return new Response<T>(true, code, message, data);
	}

	/**
	 * @return Response<String>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static Response<String> error() {
		return new Response(false, "");
	}

	/**
	 * @return Response<String>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static Response<String> error(String message) {
		return new Response(false, message);
	}

	/**
	 * @return Response<T>
	 * @author chenwb
	 * @date 2020/1/30 15:02
	 */
	public static <T> Response<T> error(String code, String message, T data) {
		return new Response<T>(false, code, message, data);
	}


	/**
	 * Message Type.
	 */
	public enum Type {
		/**
		 * success.
		 */
		SUCCESS,
		/**
		 * warn.
		 */
		WARN,
		/**
		 * error.
		 */
		ERROR
	}

	/**
	 * 获取success
	 *
	 * @return success
	 */
	public Boolean getSuccess() {
		return success;
	}

	/**
	 * 设置success
	 *
	 * @param success success
	 */
	public void setSuccess(Boolean success) {
		this.success = success;
	}

	/**
	 * 获取code
	 *
	 * @return code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * 设置code
	 *
	 * @param code code
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * 获取data
	 *
	 * @return data
	 */
	public T getData() {
		return data;
	}

	/**
	 * 设置data
	 *
	 * @param data data
	 */
	public void setData(T data) {
		this.data = data;
	}

	/**
	 * 获取message
	 *
	 * @return message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * 设置message
	 *
	 * @param message message
	 */
	public void setMessage(String message) {
		this.message = message;
	}
}
